package com.rtx.test;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.annotation.TableName;

public class CodeHelp {

	public static void main(String[] args) {
//		String temp = "";
//		checkField(temp,PlExpressApiConfig.class);

//		String temp = "";
//		checkField(temp,PlExpressApiConfig.class);
		
		testWrappers();
	}
	
	public static void testWrappers() {
		
	}
	
	public static void checkField(String str,Class clazz) {
		List<String> columnList = Arrays.asList(str.split(","));
		List<String> list  = columnList.stream().map(temp->camelCaseForMate(temp)).collect(Collectors.toList());
		for(Field field:clazz.getDeclaredFields()) {
			if(!list.contains(field.getName())) {
				TableName tableName = (TableName) clazz.getDeclaredAnnotation(TableName.class);
				System.out.println("alter table "+tableName.value()+" add " +xX2x_x(field.getName())+" varchar(255);");
			}
		}
	}
	
	public static String camelCaseForMate(String str) {
		List<String> list1 = Arrays.asList(str.split("_"));
		StringBuffer sb = new StringBuffer();
		for(String s:list1) {
			if(list1.indexOf(s)!=0) {
				sb.append(s.substring(0, 1).toUpperCase()+s.substring(1));
			}else{
				sb.append(s);
			}
		}
		return sb.toString();
	}
	
    public static String xX2x_x(String str) {
        Pattern compile = Pattern.compile("[A-Z]");
        Matcher matcher = compile.matcher(str);
        StringBuffer sb = new StringBuffer();
        while(matcher.find()) {
            matcher.appendReplacement(sb,  "_" + matcher.group(0).toLowerCase());
        }
        matcher.appendTail(sb);
        return sb.toString();
    }
}
